package io;

import java.io.*;

/**
 * 使用缓冲流完成文件复制
 */
public class CopyDemo3 {
    public static void main(String[] args) throws IOException {

        /*FileInputStream fis = new FileInputStream("./picture.jpg");
        FileOutputStream fos = new FileOutputStream("./picture_cy.jpg");
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        long start = System.currentTimeMillis();

        int d ;
        while((d=bis.read())!=-1){
            bos.write(d);
        }
        long end = System.currentTimeMillis();
        System.out.println("文件复制完毕，耗时："+(end-start)+"ms");
        bis.close();//关闭高级流时顺便关闭低级流
        bos.close();*/
        FileInputStream fis = new FileInputStream("./picture.jpg");
        FileOutputStream fos = new FileOutputStream("./picture_cy.jpg");
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        long startTime = System.currentTimeMillis();
        int flag ;
        while((flag=bis.read())!=-1){
            bos.write(flag);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("文件复制完毕，耗时"+(endTime-startTime)+"ms");
        bis.close();
        bos.close();
    }
}
